package com.ruoyi.web.controller.credit;

import java.util.List;

import com.ruoyi.credit.domain.EvaTaskDetail;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.EvaTaskResult;
import com.ruoyi.credit.service.IEvaTaskResultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价结果Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/taskResult")
public class EvaTaskResultController extends BaseController
{
    private String prefix = "credit/taskResult";

    @Autowired
    private IEvaTaskResultService evaTaskResultService;

    @RequiresPermissions("credit:taskResult:view")
    @GetMapping()
    public String taskResult()
    {
        return prefix + "/taskResult";
    }

    /**
     * 查询评价结果列表
     */
    @RequiresPermissions("credit:taskResult:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaTaskResult evaTaskResult)
    {
        startPage();
        List<EvaTaskResult> list = evaTaskResultService.selectEvaTaskResultList(evaTaskResult);
        return getDataTable(list);
    }

    /**
     * 导出评价结果列表
     */
    @RequiresPermissions("credit:taskResult:export")
    @Log(title = "评价结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaTaskResult evaTaskResult)
    {
        List<EvaTaskResult> list = evaTaskResultService.selectEvaTaskResultList(evaTaskResult);
        ExcelUtil<EvaTaskResult> util = new ExcelUtil<EvaTaskResult>(EvaTaskResult.class);
        return util.exportExcel(list, "评价结果数据");
    }

    /**
     * 新增评价结果
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评价结果
     */
    @RequiresPermissions("credit:taskResult:add")
    @Log(title = "评价结果", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EvaTaskResult evaTaskResult)
    {
        return toAjax(evaTaskResultService.insertEvaTaskResult(evaTaskResult));
    }

    /**
     * 修改评价结果
     */
    @RequiresPermissions("credit:taskResult:edit")
    @GetMapping("/edit/{taskResuletId}")
    public String edit(@PathVariable("taskResuletId") Long taskResuletId, ModelMap mmap)
    {
        EvaTaskResult evaTaskResult = evaTaskResultService.selectEvaTaskResultByTaskResuletId(taskResuletId);
        mmap.put("evaTaskResult", evaTaskResult);
        return prefix + "/edit";
    }

    /**
     * 修改保存评价结果
     */
    @RequiresPermissions("credit:taskResult:edit")
    @Log(title = "评价结果", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EvaTaskResult evaTaskResult)
    {
        return toAjax(evaTaskResultService.updateEvaTaskResult(evaTaskResult));
    }

    /**
     * 删除评价结果
     */
    @RequiresPermissions("credit:taskResult:remove")
    @Log(title = "评价结果", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaTaskResultService.deleteEvaTaskResultByTaskResuletIds(ids));
    }

    /**
     * 查看详情页面
     */
    @GetMapping("/detail/{taskResuletId}")
    public String detail(@PathVariable("taskResuletId") Long taskResuletId, ModelMap mmap)
    {
        EvaTaskResult evaTaskResult = evaTaskResultService.selectEvaTaskResultByTaskResuletId(taskResuletId);
        mmap.put("evaTaskResult", evaTaskResult);
        List<EvaTaskResult> list = evaTaskResultService.selectEvaTaskResultListDetail(evaTaskResult);
        mmap.put("detailList", list);
        return prefix + "/detail";
    }
}
